package cn.hao.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.hao.dao.TSetMapper;
import cn.hao.model.TSet;
import cn.hao.service.TSetService;

@Service("tSetService")
public class TSetServiceImpl implements TSetService {
	
	@Resource
	private TSetMapper TSMapper;

	@Override
	public List<TSet> selectByParentId(Long parentId) {
		return TSMapper.selectByParentId(parentId);
	}

	@Override
	public TSet selectByPrimaryKey(Long id) {
		return TSMapper.selectByPrimaryKey(id);
	}

	@Override
	public void addTSet(TSet tSet) {
		
		tSet.setContent("内容");
		tSet.setParent(false);
		if(tSet.getParentId()==0){
			tSet.setParent(true);
		}
		tSet.setSortOrder(1);
		tSet.setStatus(1);
		TSMapper.addTSet(tSet);
		
	}

	@Override
	public void updateByPrimaryKey(TSet tSet) {
		TSMapper.updateByPrimaryKey(tSet);
		
	}

	@Override
	public void deleteByPrimaryKey(Long id) {
		TSet ts = TSMapper.selectByPrimaryKey(id);
		//删除父类的子类
		if(ts.isParent()){
			List<TSet> tsList = TSMapper.selectByParentId(ts.getId());
			for(TSet l : tsList){
				TSMapper.deleteByPrimaryKey(l.getId());
			}
		}
		TSMapper.deleteByPrimaryKey(id);
		
	}

}
